﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ddbs.QE.Parser.Front
{
    public enum PredType{EQ=1,LH,GH,LE,GE};
    public class Col {
        string tableName;

        public string TableName
        {
            get { return tableName; }
            set { tableName = value; }
        }
        string colName;

        public string ColName
        {
            get { return colName; }
            set { colName = value; }
        }
    }
    public class Val {
        string sVal;

        public string SVal
        {
            get { return sVal; }
            set { sVal = value; }
        }
        int iVal;

        public int IVal
        {
            get { return iVal; }
            set { iVal = value; }
        }
    }
    public class SimplePred
    {
        Col lCol, rCol;

        public Col LCol
        {
            get { return lCol; }
            set { lCol = value; }
        }

        public Col RCol
        {
            get { return rCol; }
            set { rCol = value; }
        }
        Val lVal, rVal;

        public Val RVal
        {
            get { return rVal; }
            set { rVal = value; }
        }

        public Val LVal
        {
            get { return lVal; }
            set { lVal = value; }
        }
        PredType pred;

        internal PredType Pred
        {
            get { return pred; }
            set { pred = value; }
        }
        int usage;

        public int Usage
        {
            get { return usage; }
            set { usage = value; }
        }

    }
    public class Term {
        
        int andOrNot;

        public int AndOrNot
        {
            get { return andOrNot; }
            set { andOrNot = value; }
        }
        SimplePred sPred;

        public SimplePred SPred
        {
            get { return sPred; }
            set { sPred = value; }
        }
        Term rTerm;

        public Term RTerm
        {
            get { return rTerm; }
            set { rTerm = value; }
        }
    }
    
    public class Select {

        public Select()
        {
            cols = new LinkedList<Col>();
            tables = new LinkedList<string>();
            root = new Term();
        }
        bool isAll;

        public bool IsAll
        {
            get { return isAll; }
            set { isAll = value; }
        }
        LinkedList<Col> cols;           //table.col

        public LinkedList<Col> Cols
        {
            get { return cols; }
            set { cols = value; }
        }



        LinkedList<string> tables;

        public LinkedList<string> Tables
        {
            get { return tables; }
            set { tables = value; }
        }

        


        Term root;

        public Term Root
        {
            get { return root; }
            set { root = value; }
        }
    }
    public class SelectHelper
    {
        private static LinkedList<Select> selects;

        public static LinkedList<Select> Selects
        {
            get { return SelectHelper.selects; }
            set { SelectHelper.selects = value; }
        }

       
        public static void createSelect()
        {
            Select s = new Select();
            if (Selects == null)
            {
                selects = new LinkedList<Select>();
            }
            selects.AddLast(s);
        }
        public static void setIsAll(Select select, bool isAll) {
            select.IsAll = isAll;
        }
        public static void addCols(Select select, string tableName, string colName)
        {
            Col col = new Col();
            col.ColName = colName;
            col.TableName = tableName;
            select.Cols.AddLast(col);
        }
        public static void addTables(Select select, string tableName)
        {
            select.Tables.AddLast(tableName);
        }
        public static void createRoot(Select select, int andOrNot)
        {
            select.Root.AndOrNot = andOrNot;
        }

    }
}
